#include <json.hpp>
#include <iostream>
#include <string>

int main(int argc, char *argv[]) {
  json_malloc_t jMalloc = nullptr;
  json_free_t jFree = nullptr;
  json_get_alloc_funcs(&jMalloc, &jFree);
  if (!jMalloc || !jFree) {
    std::cout << "json error." << std::endl;
    return -1;
  }

  auto obj = json_object();
  json_object_set_new(obj, "key", json_string("value"));
  auto str = json_dumps(obj, JSON_COMPACT);
  if (str) {
    std::cout << str << std::endl;
  }

  std::cout << (int)str << "," << (strlen(str)+1) << std::endl;
  system("pause");

  jFree(str);
  str = nullptr;

  json_decref(obj);
  return 0;
}